/*
 * Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://mindorks.com/license/apache-v2
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package org.changs.game.android.data.prefs;


import android.content.Context;
import android.content.SharedPreferences;

import org.changs.game.android.di.ApplicationContext;
import org.changs.game.android.di.PreferenceInfo;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class AppPreferencesHelper implements PreferencesHelper {

    private static final String PREF_KEY_BOOK_VERSION = "PREF_KEY_BOOK_VERSION";
    private static final String PREF_KEY_BOOK_AUDIO = "PREF_KEY_BOOK_AUDIO";
    private static final String PREF_KEY_INITIALIZED = "PREF_KEY_INITIALIZED";

    private final SharedPreferences mPrefs;

    @Inject
    public AppPreferencesHelper(@ApplicationContext Context context,
                                @PreferenceInfo String prefFileName) {
        mPrefs = context.getSharedPreferences(prefFileName, Context.MODE_PRIVATE);
    }


    @Override
    public String getBookVersion() {
        return mPrefs.getString(PREF_KEY_BOOK_VERSION, "0");
    }

    @Override
    public void setBookVersion(String version) {
        mPrefs.edit().putString(PREF_KEY_BOOK_VERSION, version).apply();
    }

    @Override
    public String getAudioType() {
        return mPrefs.getString(PREF_KEY_BOOK_AUDIO, AUDIO_EN);
    }

    @Override
    public void setAudioType(String type) {
        mPrefs.edit().putString(PREF_KEY_BOOK_AUDIO, type).apply();
    }

    @Override
    public void setInitialized(boolean initialized) {
        mPrefs.edit().putBoolean(PREF_KEY_INITIALIZED, initialized).apply();
    }

    @Override
    public boolean getInitialized() {
        return mPrefs.getBoolean(PREF_KEY_INITIALIZED, false);
    }
}
